<template>
    <div>
        <Modal width="820"
               v-model="modal.editTeacherFlag"
               @on-cancel="cancel"
               title="添加教师">
            <div class="modalDiv"></div>
            <Form ref="teacher" :model="modal.teacher" inline :label-width="100">
                <FormItem prop="worker" label="工号">
                    <Input class="myform" v-model="modal.teacher.worker" clearable/>
                </FormItem>
                <FormItem prop="name" label="名称">
                    <Input class="myform" v-model="modal.teacher.name" clearable/>
                </FormItem>
                <FormItem prop="sex" label="性别">
                    <Select v-model="modal.teacher.sex" clearable class="myform">
                        <Option value="男">男</Option>
                        <Option value="女">女</Option>
                    </Select>
                </FormItem>
                <FormItem prop="birthday" label="出生年月日">
                    <DatePicker class="myform" type="date" v-model="modal.teacher.birthday" clearable/>
                </FormItem>
                <FormItem prop="position" label="职称">
                    <Input class="myform" v-model="modal.teacher.position" clearable/>
                </FormItem>
                <FormItem prop="collegeId" label="学院">
                    <Select v-model="modal.teacher.collegeId" clearable class="myform">
                        <Option  v-for="item in modal.list" :value="item.collegeId" :key="item.collegeId">{{item.name}}</Option>
                    </Select>
                </FormItem>
            </Form>
            <Button type="primary" slot="footer" @click="ok" :loading="loading">提交</Button>
        </Modal>
    </div>
</template>

<script>

    export default {
        name: "editTeacher",
        props: {
            modal: {
                editTeacherFlag: false,
                teacher:{},
                list:[]
            }
        },
        data() {
            return {
                loading: false,
            }
        },
        methods: {
            ok() {
                    this.loading = true
                    this.modal.teacher.birthday = new Date(this.modal.teacher.birthday).toLocaleDateString()
                    this.http.put('/teacher/saveEditTeacher', this.qs.parse(this.modal.teacher)).then(res => {
                        if (res) {
                            this.$Message['success']({
                                background: true,
                                content: '编辑成功'
                            });
                            this.modal.editTeacherFlag = false;
                            this.loading = false;
                            this.$parent.getAllTeacher();
                        }
                    }).finally(r=>{
                        this.loading = false
                    })
            },
            cancel() {

            },
        },
        created() {
        }
    }
</script>

<style scoped>
    .myform {
        width: 280px;
    }
</style>
